package com.ruoyi.web.controller.common;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.system.utils.ALiYunFileHelper;

@Slf4j
@RestController
@Api(tags = "FileController", description = "文件上传接口")
@RequestMapping("/sms/file")
public class FileController {
	
	@ApiOperation(value = "图片上传接口")
	@CrossOrigin(origins = "*", maxAge = 3600)
	@PostMapping("/uploadPic")
	public String fileTest(@RequestParam(value = "file", required = true) MultipartFile file, HttpServletResponse response) {
		response.setCharacterEncoding("utf-8");
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods",
				"POST, GET, OPTIONS, DELETE");
		// //请求包含的字段内容，如有多个可用哪个逗号分隔如下
		response.setHeader("Access-Control-Allow-Headers",
				"content-type,x-requested-with,Authorization, x-ui-request,lang");
		// //访问控制允许凭据，true为允许
		response.setHeader("Access-Control-Allow-Credentials", "true");
		String str = ALiYunFileHelper.picOSS(file);
		return str;
	}
	
	

}
